/**
 * Description:
 * Class Name:SearchTest
 * Date:2022/3/14 16:06
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第8章_Java集合._8_8_操作集合的工具类_Collections._8_8_2_查询与替换操作;

import java.util.ArrayList;
import java.util.Collections;

public class SearchTest {
    public static void main(String[] args) {
        var nums = new ArrayList();
        nums.add(2);
        nums.add(-5);
        nums.add(3);
        nums.add(0);
        System.out.println(nums);

        System.out.println(Collections.max(nums));
        System.out.println(Collections.min(nums));

        Collections.replaceAll(nums, 0, 1);
        System.out.println(nums);

        // 判断-5在List集合中出现的次数，返回1
        System.out.println(Collections.frequency(nums, -5));

        // 对集合进行排序后才可以使用二分法搜索
        Collections.sort(nums);
        System.out.println(nums);
        System.out.println(Collections.binarySearch(nums, 3));
    }
}
